home *** CD-ROM | disk | FTP | other *** search
- /*==================================================================
- File: MacZStringFileSpec.h
-
- Contains: Helper class for storing and managing a file
- spec within the ZString tool.
-
- Written by: Eric Traut
-
- Copyright: 2000-2001 Connectix Corporation
-
- This source has been placed into the public domain by
- Connectix Corporation. You have the right to modify,
- distribute or use this code without any legal limitations
- or finanicial/licensing requirements. Connectix is not
- liable for any problems that result from the use of this
- code.
-
- If you have comments, feedback, questions, or would like
- to submit bug fixes or updates to this code, please email
- opensource@connectix.com.
- ==================================================================*/
-
- #pragma once
-
- #include <Icons.h>
- #include <Files.h>
-
-
- class MacZStringFileSpec
- {
- public:
- MacZStringFileSpec()
- {
- mIconRef = NULL;
- mSpecIsValid = false;
- }
-
- ~MacZStringFileSpec()
- {
- ReleaseIconRef();
- }
-
- void
- ReleaseIconRef()
- {
- if (::IsValidIconRef(mIconRef))
- ::ReleaseIconRef(mIconRef);
- mIconRef = NULL;
- }
-
- void
- SetFileSpec(
- const FSSpec & inFileSpec)
- {
- mFileSpec = inFileSpec;
- mSpecIsValid = true;
- ReleaseIconRef();
- }
-
- void
- ClearFileSpec()
- {
- mSpecIsValid = false;
- ReleaseIconRef();
- }
-
- Boolean
- IsValid() const
- {
- return mSpecIsValid;
- }
-
- const FSSpec &
- GetFSSpec()
- {
- return mFileSpec;
- }
-
- operator const FSSpec & ()
- {
- return mFileSpec;
- }
-
- IconRef
- GetIconRef()
- {
- if (mIconRef == NULL)
- {
- SInt16 label;
-
- // Make sure the file exists first.
- FSSpec dummySpec;
- OSErr err = ::FSMakeFSSpec(mFileSpec.vRefNum, mFileSpec.parID, mFileSpec.name, &dummySpec);
-
- if (err == noErr)
- {
- err = ::GetIconRefFromFile(&mFileSpec, &mIconRef, &label);
- SignalIf_(err != noErr);
- }
- }
-
- return mIconRef;
- }
-
- private:
- FSSpec mFileSpec;
- Boolean mSpecIsValid;
- IconRef mIconRef;
- };
-
-
-
-